package com.ss.android.article.base.feature.app.schema;

import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;

import com.bytedance.common.utility.Logger;
import com.bytedance.frameworks.b.a.ComponentsManifest;
import com.ss.android.article.base.app.SingleAppData;
import com.ss.android.article.base.feature.detail2.DetailIntentCreator;
import com.ss.android.article.base.feature.message.MessageTabActvity;
import com.ss.android.article.base.feature.pgc.PgcActivity;
import com.ss.android.article.base.feature.subscribe.activity.EntryGroupListActivity;
import com.ss.android.article.base.feature.update.activity.UpdateDetailActivity;
import com.ss.android.common.applog.AppLog;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.common.util.json.JsonUtil;
import com.ss.android.common.util.ToolUtils;
import com.ss.android.newmedia.a.AdsAppBaseActivity;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class AdsAppActivity extends AdsAppBaseActivity {
    private static Set<String> j;

    static {
        AdsAppActivity.j = new HashSet();
        AdsAppActivity.j.add("feedback");
        AdsAppActivity.j.add("webview");
        AdsAppActivity.j.add("home");
        AdsAppActivity.j.add("detail");
        AdsAppActivity.j.add("search");
        AdsAppActivity.j.add("more");
        AdsAppActivity.j.add("notification");
        AdsAppActivity.j.add("msg");
        AdsAppActivity.j.add("favorite");
        AdsAppActivity.j.add("add_entry");
        AdsAppActivity.j.add("media_account");
        AdsAppActivity.j.add("pgcprofile");
        AdsAppActivity.j.add("wenda_list");
        AdsAppActivity.j.add("wenda_list_more");
        AdsAppActivity.j.add("wenda_detail");
        AdsAppActivity.j.add("talk");
        AdsAppActivity.j.add("login");
        AdsAppActivity.j.add("main_feed");
    }

    public static boolean a(String arg1) {
        return !android.support.design.a.isTextEmpty(arg1) && AdsAppActivity.j.contains(arg1);
    }

    private Intent a(Intent arg3) {
        String v0 = this.g("api_param");
        if (!TextUtils.isEmpty(v0)) {
            arg3.putExtra("api_param", v0);
        }

        return arg3;
    }

    public final void startAppActivity() {
        Object v0_4;
        if (Logger.debug()) {
            Logger.d("AdsAppActivity", "startAppActivity start");
        }

        Intent intent = this.d();
        Intent v1 = intent == null ? ToolUtils.getLaunchIntentForPackage(this, this.getPackageName()) : intent;
        try {
            if (this.g) {
                v1.putExtra("from_notification", true);
                if (!android.support.design.a.isTextEmpty(this.notificationSource)) {
                    v1.putExtra("notification_source", this.notificationSource);
                }

                AppLog.o = 2;
            }

            boolean stayOriginTask = this.a(this.extraSchemaUri);
            if (this.f) {
                v1.putExtra("stay_tt", 1);
            } else if (this.isActivityInThirdAppTask()) {
                if (Logger.debug()) {
                    Logger.d("AdsAppActivity", "isActivityInThirdAppTask = true");
                }

                if (stayOriginTask) {
                    if (Logger.debug()) {
                        Logger.d("AdsAppActivity", "stayOriginTask = true");
                    }
                    v1.putExtra("stay_tt", 0);
                } else {
                    if (Logger.debug()) {
                        Logger.d("AdsAppActivity", "stayOriginTask = false");
                    }
                    v1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    v1.putExtra("stay_tt", 1);
                }
            } else {
                if (Logger.debug()) {
                    Logger.d("AdsAppActivity", "isActivityInThirdAppTask = false");
                }

                if (!stayOriginTask) {
                    if (Logger.debug()) {
                        Logger.d("AdsAppActivity", "stayOriginTask = false");
                    }
                    v1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    v1.putExtra("stay_tt", 1);
                } else {
                    if (Logger.debug()) {
                        Logger.d("AdsAppActivity", "stayOriginTask = true");
                    }

                    v1.putExtra("stay_tt", 0);
                    List<ActivityManager.RecentTaskInfo> v0_3 = ((ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE)).getRecentTasks(2, 2);
                    if (v0_3 == null) {
                        v0_4 = null;
                    } else if (v0_3.size() > 1) {
                        v0_4 = v0_3.get(1);
                    } else {
                        v0_4 = null;
                    }
                    if (v0_4 == null) {
                    } else if (((ActivityManager.RecentTaskInfo) v0_4).baseIntent == null) {
                    } else {
                        v1.putExtra("previous_task_id", ((ActivityManager.RecentTaskInfo) v0_4).id);
                        v1.putExtra("previous_task_intent", ((ActivityManager.RecentTaskInfo) v0_4).baseIntent.toUri(1));
                    }
                }
            }
            this.startActivity(v1);
            if (Logger.debug()) {
                Logger.d("AdsAppActivity", "startAppActivity end");
            }
        } catch (Exception v0_1) {
            Logger.e("ads app activity", "start error" + v0_1.toString());
        }


    }

    public final boolean a(Uri arg6) {
        boolean v0 = false;
        if (arg6 != null) {
            String v2 = arg6.getQueryParameter("gd_label");
            if (!"detail".equals(arg6.getHost())) {
                return v0;
            }

            if ("baidu_inapp".equals(v2)) {
                return true;
            }

            if ("toutiao_yy".equals(v2)) {
                return true;
            }

            try {
                if (!"0".equals(arg6.getQueryParameter("stay_tt"))) {
                    return v0;
                }
            } catch (Exception v1) {
                return v0;
            }

            v0 = true;
        }

        return v0;
    }

    @TargetApi(value = 11)
    private static void b(Intent arg1) {
        if (arg1 != null) {
            arg1.addFlags(67108864);
            arg1.addFlags(536870912);
            arg1.addFlags(32768);
        }
    }

    private Intent d() {
        Intent v5_3;
        int v11;
        int v10_1;
        int v5_2;
        long v6_2;
        long v8_1;
        String v7_1;
        String v6_1;
        Intent v21;
        String v20;
        String v4_2;
        boolean v5_1;
        boolean v6;
        long v18;
        long v16;
        long v14;
        long v12;
        int v7;
        String v5;
        Intent v4 = null;
        if (Logger.debug()) {
            Logger.d("AdsAppActivity", "getAppIntent start");
        }

        try {
            if ("home".equals(this.b)) {
                v4 = null;
                if ("/news".equals(this.c)) {
                    v4 = SingleAppData.aw().ax();
                    v4.putExtra("open_category_name", "__all__");
                }

                if ("/activity".equals(this.c)) {
                    v4 = SingleAppData.aw().ax();
                    v4.putExtra("view_update", true);
                }

                if ("/category".equals(this.c)) {
                    v4 = SingleAppData.aw().ax();
                    v4.putExtra("view_category", true);
                }

                AdsAppActivity.b(v4);
                v5 = this.extraSchemaUri == null ? "" : this.extraSchemaUri.getQueryParameter("growth_from");
                if (android.support.design.a.isTextEmpty(v5)) {
                } else {
                    MobClickCombiner.onEvent(this, "launch", v5);
                }
            }
            if ("detail".equals(this.b)) {
                if (Logger.debug()) {
                    Logger.d("AdsAppActivity", "detail start");
                }

                v7 = this.a("group_flags", 0);
                int v8 = this.a("article_type", -1);
                long v10 = this.d("flags");
                v12 = this.e("groupid");
                v14 = this.d("item_id");
                int v9 = this.a("aggr_type", 0);
                v16 = this.e("ad_id");
                v18 = this.e("from_gid");
                v6 = this.extraSchemaUri == null || !AdsAppActivity.h(this.extraSchemaUri.getQueryParameter("showcomment")) ? false : true;
                v5_1 = this.extraSchemaUri == null || !AdsAppActivity.h(this.extraSchemaUri.getQueryParameter("no_hw")) ? false : true;
                if (v12 <= 0) {

                } else {
                    v4_2 = this.g("gd_label");
                    v20 = this.g("article_url");
                    v21 = new Intent();
                    v21.putExtra("view_single_id", true);
                    v21.putExtra("group_id", v12);
                    v21.putExtra("item_id", v14);
                    v21.putExtra("aggr_type", v9);
                    v21.putExtra("group_flags", v7);
                    v21.putExtra("article_type", v8);
                    v21.putExtra("flags", v10);
                    v21.putExtra("enter_from", this.g("enter_from"));
                    v21.putExtra("from_gid", v18);
                    v21.putExtra("extra_schema_uri", this.extraSchemaUri);
                    if (!android.support.design.a.isTextEmpty(v4_2)) {
                        v21.putExtra("detail_source", v4_2);
                    } else if (this.g) {
                        switch (this.i) {
                            case 1: {
                                v21.putExtra("detail_source", "click_news_notify");
                                break;
                            }
                            case 2: {
                                v21.putExtra("detail_source", "click_news_alert");
                                break;
                            }
                        }
                    }
                    if (v16 > 0) {
                        v21.putExtra("ad_id", v16);
                        if (!android.support.design.a.isTextEmpty(v20)) {
                            v21.putExtra("article_url", v20);
                        }

                        if (android.support.design.a.isTextEmpty(this.d)) {
                        } else {
                            v21.putExtra("bundle_download_app_extra", this.d);
                        }
                    }
                    if (v5_1) {
                        v21.putExtra("bundle_no_hw_acceleration", v5_1);
                    }

                    if (v6) {
                        v21.putExtra("is_jump_comment", v6);
                    }

                    if (Logger.debug()) {
                        Logger.d("AdsAppActivity", "detail end");
                    }

                    if ((android.support.design.a.b(v10)) || (android.support.design.a.b(((long) v7)))) {
                        v4 = ((DetailIntentCreator) ComponentsManifest.findComponent(DetailIntentCreator.class)).createNewVideoDetailIntent(this, v21.getExtras());
                    } else {
                        v4 = ComponentsManifest.findComponent(DetailIntentCreator.class).createNewDetailIntent(this, v21.getExtras());
                    }
                }
            }

            if ("search".equals(this.b)) {
                if (this.extraSchemaUri == null) {
                    v4 = null;
                } else {
                    v4 = new Intent();
                    v5 = this.isTaskRoot() ? "com.ss.android.article.base.feature.search.SearchActivityAlias" : "com.ss.android.article.base.feature.search.SearchActivity";
                    v4.setClassName(this, v5);
                    v4.putExtra("keyword", this.extraSchemaUri.getQueryParameter("keyword"));
                    v4.putExtra("from", this.extraSchemaUri.getQueryParameter("from"));
                }
            }

            if ("more".equals(this.b)) {
                v4 = new Intent();
                v4.setClassName(this, "com.ss.android.mine.BaseSettingActivity");
                v4.putExtra("tag", "news");
            }

            if ("notification".equals(this.b)) {
                v4 = MessageTabActvity.b(this, "notify");
            }

            if ("msg".equals(this.b)) {
                v4 = MessageTabActvity.b(this, "reply");
            }

            if ("favorite".equals(this.b)) {
                v4 = new Intent();
                v4.setClassName(this, "com.ss.android.article.base.feature.favorite.FavoriteActivity");
                v4.addFlags(131072);
            }

            if ("add_entry".equals(this.b)) {
                if ("feed_header_footer_click".equals(this.g("enter_from"))) {
                    JSONObject v12_1 = new JSONObject();
                    v12_1.put("source", "card");
                    MobClickCombiner.onEvent(this, "subscription", "enter", this.e("card_id"), 0, v12_1);
                }

                v4 = new Intent(this, EntryGroupListActivity.class);
            }

            if ("category_feed".equals(this.b)) {
                v5 = this.g("category");
                v6_1 = this.g("type");
                v7_1 = this.g("name");
                if (!android.support.design.a.isTextEmpty(v5)) {
                    v4 = SingleAppData.aw().ax();
                    AdsAppActivity.b(v4);
                    v4.putExtra("open_category_name", v5);
                    if (!android.support.design.a.isTextEmpty(v6_1)) {
                        v4.putExtra("open_category_type", v6_1);
                    }

                    if (android.support.design.a.isTextEmpty(v7_1)) {
                    } else {
                        v4.putExtra("open_category_title", v7_1);
                    }
                }
            }
            if (("media_account".equals(this.b)) || ("pgcprofile".equals(this.b))) {
                v4 = new Intent(this, PgcActivity.class);
                v8_1 = this.e("entry_id");
                v6_2 = this.e("media_id");
                v5 = this.g("gd_ext_json");
                if (v6_2 == -1) {
                    v6_2 = this.e("mediaid");
                }

                if (v8_1 > 0) {
                    v4.putExtra("mediaid", v8_1);
                } else if (v6_2 > 0) {
                    v4.putExtra("mediaid", v6_2);
                }

                if (!android.support.design.a.isTextEmpty(v5)) {
                    v4.putExtra("gd_ext_json", v5);
                }

                v5_2 = -1;
                if (!android.support.design.a.isTextEmpty(this.extraSchemaUri.getQueryParameter("page_type"))) {
                    v5_2 = this.f("page_type");
                }

                if (v5_2 >= 0) {
                    v4.putExtra("page_type", v5_2);
                }

                v4.putExtra("use_swipe", true);
            }

            if ("wenda_list".equals(this.b)) {
                v4 = com.ss.android.article.common.b.b.a().a(this);
                if (v4 != null) {
                    v4.putExtra("gd_ext_json", JsonUtil.a(JsonUtil.a(this.e(), "scope", this.g("scope")), "ansid", this.g("enterfrom_answerid")));
                    v4.putExtra("qid", this.g("qid"));
                    v4 = this.a(v4);
                }
            }

            if ("wenda_list_more".equals(this.b)) {
                v4 = com.ss.android.article.common.b.b.a().b(this);
                if (v4 != null) {
                    v4.putExtra("gd_ext_json", this.e());
                    v4.putExtra("qid", this.g("qid"));
                    v4 = this.a(v4);
                }
            }

            if ("wenda_detail".equals(this.b)) {
                v10_1 = this.a("group_flags", 0);
                v11 = this.a("article_type", -1);
                v12 = this.d("flags");
                v6_2 = this.e("ansid");
                if (v6_2 == -1) {
                    v8_1 = this.e("groupid");
                } else {
                    v8_1 = v6_2;
                }

                v14 = this.d("item_id");
                v7 = this.a("aggr_type", 0);
                v16 = this.e("ad_id");
                v18 = this.e("from_gid");
                v6 = this.extraSchemaUri == null || !AdsAppActivity.h(this.extraSchemaUri.getQueryParameter("showcomment")) ? false : true;
                v5_1 = this.extraSchemaUri == null || !AdsAppActivity.h(this.extraSchemaUri.getQueryParameter("no_hw")) ? false : true;
                if (v8_1 > 0) {
                    v4_2 = this.g("gd_label");
                    v20 = this.g("article_url");
                    v21 = new Intent();
                    v21.putExtra("view_single_id", true);
                    v21.putExtra("group_id", v8_1);
                    v21.putExtra("item_id", v14);
                    v21.putExtra("aggr_type", v7);
                    v21.putExtra("group_flags", v10_1);
                    v21.putExtra("article_type", v11);
                    v21.putExtra("flags", v12);
                    v21.putExtra("enter_from", this.g("enter_from"));
                    v21.putExtra("from_gid", v18);
                    v21.putExtra("gd_ext_json", JsonUtil.a(this.e(), "scope", this.g("scope")));
                    if (!android.support.design.a.isTextEmpty(v4_2)) {
                        v21.putExtra("detail_source", v4_2);
                    } else if (this.g) {
                        switch (this.i) {
                            case 1: {
                                v21.putExtra("detail_source", "click_news_notify");
                                break;
                            }
                            case 2: {
                                v21.putExtra("detail_source", "click_news_alert");
                                break;
                            }
                        }
                    }
                    if (v16 > 0) {
                        v21.putExtra("ad_id", v16);
                        if (!android.support.design.a.isTextEmpty(v20)) {
                            v21.putExtra("article_url", v20);
                        }

                        if (android.support.design.a.isTextEmpty(this.d)) {
                        } else {
                            v21.putExtra("bundle_download_app_extra", this.d);
                        }
                    }

                    if (v5_1) {
                        v21.putExtra("bundle_no_hw_acceleration", v5_1);
                    }

                    if (v6) {
                        v21.putExtra("is_jump_comment", v6);
                    }

                    v4 = com.ss.android.article.common.b.b.a().a(this, (Bundle) null);
                    v4.putExtras(v21.getExtras());
                    v4 = this.a(v4);
                }
            }
            if (!"talk".equals(this.b)) {

            } else {
                v5_3 = new Intent(this, UpdateDetailActivity.class);
                v5_3.putExtra("id", Long.valueOf(this.g("id")).longValue());
                try {
                    int v4_4 = Integer.valueOf(this.g("is_from_u11")).intValue();
                    if (v4_4 > 0) {
                        v5_3.putExtra("is_from_u11", v4_4);
                        v5_3.putExtra("item_id", Long.valueOf(this.g("item_id")).longValue());
                    }
                } catch (NumberFormatException v4_3) {
                    v4_3.printStackTrace();
                }
                v4 = v5_3;
            }
            if ("login".equals(this.b)) {
                v5_3 = null;
                v4_2 = this.g("platform");
                if (!TextUtils.isEmpty(((CharSequence) v4_2))) {
                    int v6_3 = -1;
                    switch (v4_2.hashCode()) {
                        case -1068855134: {
                            if (v4_2.equals("mobile")) {
                                v6_3 = 0;
                            } else {
                            }

                            break;
                        }
                        case -791575966: {
                            if (v4_2.equals("weixin")) {
                                v6_3 = 1;
                            } else {
                            }

                            break;
                        }
                        case 3616: {
                            if (v4_2.equals("qq")) {
                                v6_3 = 2;
                            } else {
                            }

                            break;
                        }
                    }

                    switch (v6_3) {
                        case 0: {
                            label_760:
                            v6_1 = "mobile";
                        }
                        case 1: {
                            label_763:
                            v6_1 = "weixin";
                        }
                        case 2: {
                            label_766:
                            v6_1 = "qzone_sns";
                        }
                        default:
                            v6_1 = v4_2;
                    }
                } else {
                    v6_1 = v4_2;
                }

                v7_1 = this.extraSchemaUri.getQueryParameter("title_type");
                String v8_2 = this.extraSchemaUri.getQueryParameter("login_source");
                Object v4_5 = ComponentsManifest.findComponent(com.ss.android.account.v2.bb.class);
                if (!"mobile".equals(v6_1)) {
                    if (!"weixin".equals(v6_1) && !"qzone_sns".equals(v6_1)) {
                        v4 = v5_3;
                    } else {
                        v4 = ((com.ss.android.account.v2.bb) v4_5).a(this, v6_1);
                        v4.putExtras(android.support.design.a.createJumpData(v7_1, v8_2));
                    }
                } else if (!this.e.isLogin) {
                    v4 = ((com.ss.android.account.v2.bb) v4_5).a(this, v6_1);
                    v4.putExtras(android.support.design.a.createJumpData(v7_1, v8_2));
                } else {
                    v4 = v5_3;
                }
            }
            if ("main_feed".equals(this.b)) {
                v4 = new Intent();
                v4.setComponent(new ComponentName(this.getPackageName(), "com.ss.android.article.lite.activity.MainActivity"));
                v4.addFlags(603979776);
            }
            if (v4 == null) {
                return null;
            }

            v5 = this.extraSchemaUri.getQueryParameter("growth_from");
            if (!TextUtils.isEmpty(((CharSequence) v5))) {
                v4.putExtra("growth_from", v5);
            }

            v5 = this.g("category_id");
            if (!android.support.design.a.isTextEmpty(v5)) {
                v4.putExtra("category_id", v5);
            }

            v5 = this.g("from_category");
            if (!android.support.design.a.isTextEmpty(v5)) {
                v4.putExtra("from_category", v5);
            }

            v6_1 = this.g("gd_ext_json");
            v5 = null;
            if (v4.getExtras() != null) {
                v5 = v4.getExtras().getString("gd_ext_json");
            }

            if (!android.support.design.a.isTextEmpty(v6_1) && (android.support.design.a.isTextEmpty(v5))) {
                v4.putExtra("gd_ext_json", v6_1);
            }

            v5_2 = this.f("list_type");
            if (v5_2 != -1) {
                v4.putExtra("list_type", v5_2);
            }

            v4.putExtra("swipe_mode", 2);
            AdsAppActivity.a(v4, this.extraSchemaUri);
        } catch (Exception v4_1) {
            label_678:
            v4_1.printStackTrace();
            v4 = null;
        }

        return v4;
    }

    private String e() {
        String v0 = this.g("gd_ext_json");
        if (TextUtils.isEmpty(((CharSequence) v0))) {
            JSONObject v1 = new JSONObject();
            v0 = this.g("enter_from");
            if (TextUtils.isEmpty(((CharSequence) v0))) {
                return v1.toString();
            }

            try {
                v1.put("enter_from", v0);
            } catch (JSONException v0_1) {
                v0_1.printStackTrace();
            }

            v0 = v1.toString();
        }

        return v0;
    }
}

